package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"strings"
)

func main() {
	input := "go to study go language"
	scanner := bufio.NewScanner(strings.NewReader(input))
	buf := make([]byte, 3)
	scanner.Buffer(buf, 2)
	scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		fmt.Println(string(data), atEOF)
		if bytes.Equal(data[:2], []byte("go")) {
			return 1, []byte("found"), nil
		}
		if atEOF {
			return 0, nil, io.EOF
		}
		return 1, nil, nil
	})
	for scanner.Scan() {
		fmt.Printf("%s\n", scanner.Text())
	}
}
